package cn.com.smartdevices.bracelet.chart;

import android.animation.Animator;
import android.animation.ValueAnimator;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.LinearInterpolator;

import com.goodving.guli.view.C4005t;

import cn.com.smartdevices.bracelet.chart.base.BaseChartView;

public class LinePieChartView extends BaseChartView<LinePieChart> {
    private static final String f3904a = "LinePieChartView";
    private Bitmap f3905b;
    private float f3906c;
    private Animator f3907d;

    public LinePieChartView(Context context) {
        this(context, null);
    }

    public LinePieChartView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public LinePieChartView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        this.f3847e = new LinePieChart(context);
        TypedArray obtainStyledAttributes = getContext().obtainStyledAttributes(attributeSet, C4005t.LinePieChartView);
        setMode(obtainStyledAttributes.getInt(0, 0));
        int resourceId = obtainStyledAttributes.getResourceId(1, -1);
        if (resourceId != -1) {
            this.f3905b = BitmapFactory.decodeResource(getResources(), resourceId);
            if (this.f3905b != null) {
                ((LinePieChart) this.f3847e).m8848a(this.f3905b);
            }
        }
        obtainStyledAttributes.recycle();
        this.f3855m = new DecelerateInterpolator();
        this.f3856n = 1;
    }


    class C0808y implements Animator.AnimatorListener {
        final /* synthetic */ LinePieChartView f4164a;

        C0808y(LinePieChartView linePieChartView) {
            this.f4164a = linePieChartView;
        }

        public void onAnimationCancel(Animator animator) {
        }

        public void onAnimationEnd(Animator animator) {
            ((LinePieChart) this.f4164a.f3847e).dismissLoading();
            ((LinePieChart) this.f4164a.f3847e).rotate(0.0f);
            this.f4164a.postInvalidateOnAnimation();
        }

        public void onAnimationRepeat(Animator animator) {
        }

        public void onAnimationStart(Animator animator) {
            ((LinePieChart) this.f4164a.f3847e).showLoading();
            ((LinePieChart) this.f4164a.f3847e).rotate(0.0f);
            this.f4164a.postInvalidateOnAnimation();
        }
    }

    class C0809z implements ValueAnimator.AnimatorUpdateListener {
        final /* synthetic */ LinePieChartView f4165a;

        C0809z(LinePieChartView linePieChartView) {
            this.f4165a = linePieChartView;
        }

        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            ((LinePieChart) this.f4165a.f3847e).rotate(((Float) valueAnimator.getAnimatedValue()).floatValue());
            this.f4165a.postInvalidateOnAnimation();
        }
    }



    private void m8502g() {
        float f = this.f3906c / ((LinePieChart) this.f3847e).getMaxValue();
        if (f > 1.0f) {
            f = 1.0f;
        }
        this.f3856n = (long) (Math.sqrt((double) f) * 800.0d);
        if (this.f3856n == 0) {
            this.f3856n = 1;
        }
    }

    @SuppressLint({"NewApi"})
    private Animator m8503n() {
        ValueAnimator ofFloat = ValueAnimator.ofFloat(new float[]{0.0f, 1.0f});
        ofFloat.addListener(new C0808y(this));
        ofFloat.addUpdateListener(new C0809z(this));
        ofFloat.setDuration(3500);
        ofFloat.setInterpolator(new LinearInterpolator());
        ofFloat.setRepeatMode(1);
        ofFloat.setRepeatCount(-1);
        return ofFloat;
    }

    public void setMode (int i) { // m8504a
        ((LinePieChart) this.f3847e).setMode(i);
        invalidate();
    }

    public void setMaxValue (long j) { // m8505a
        ((LinePieChart) this.f3847e).setMaxValue((float) j);
    }

    public void m8506a(RectF rectF) {
        ((LinePieChart) this.f3847e).setRect(rectF);
    }

    public void m8507b() {
        if (this.f3907d != null) {
            this.f3907d.end();
            ((LinePieChart) this.f3847e).dismissLoading();
        }
    }

    public void m8508b(int i) {
        ((LinePieChart) this.f3847e).m8854c(i);
        postInvalidate();
    }

    public void m8509b(long j) {
        this.f3906c = (float) j;
        m8502g();
    }

    public void m8510c(int i) {
        ((LinePieChart) this.f3847e).m8852b(i);
    }

    public void m8511c(long j) {
        if (this.f3907d == null) {
            this.f3907d = m8503n();
        }
        if (!this.f3907d.isStarted()) {
            if (j > 0) {
                this.f3907d.setStartDelay(j);
            }
            this.f3907d.start();
        }
    }

    public void showNormalLine () { // m8512d
        ((LinePieChart) this.f3847e).setMode(0);
        refresh(false);
    }

    public void d_() {
        m8511c(0);
    }

    public int m8513e() {
        return ((LinePieChart) this.f3847e).m8855d();
    }

    public int m8514f() {
        return ((LinePieChart) this.f3847e).m8853c();
    }

    protected void onDraw(Canvas canvas) {
        if (this.f3857o < 1.0f) {
            ((LinePieChart) this.f3847e).setValue(this.f3857o * this.f3906c);
            ((LinePieChart) this.f3847e).draw(canvas, 1.0f);
            return;
        }
        ((LinePieChart) this.f3847e).setValue(this.f3906c);
        ((LinePieChart) this.f3847e).draw(canvas, this.f3857o);
    }
}
